#!/bin/bash

# Copyright 2019 Mobvoi Inc. All Rights Reserved.

. ./path.sh || exit 1;

cd ..
stage=5 # start from 0 if you need to start from data preparation
stop_stage=6

cmvn=false
do_delta=false

#dir=/home/work_nfs7/xlgeng/bsmu_template/exp/salmonn_v8_lr5e_5
dir=
train_config=
data_type=shard # raw

average_checkpoint=false
decode_checkpoint=
decode_checkpoint_name=

decode_modes="salmonn_decode"
gpu_id=4
# test_sets="SPEECHIO_ASR_ZH00004"
test_sets=("aishell1" "aishell2" "SPEECHIO_ASR_ZH00000" "SPEECHIO_ASR_ZH00001" "SPEECHIO_ASR_ZH00002" "SPEECHIO_ASR_ZH00003" "SPEECHIO_ASR_ZH00004" "SPEECHIO_ASR_ZH00005" "test_meeting" "test_net")
shard_sets=("test_huawei_accent")

. tools/parse_options.sh || exit 1;
echo "开始打印主要变量，这些变量有命令行传入"
echo "dir=$dir"
echo "train_config=$train_config"
echo "decode_checkpoint=$decode_checkpoint"
echo "decode_checkpoint_name=$decode_checkpoint_name"
echo "gpu_id=$gpu_id"
echo "stage=$stage"
echo "stop_stage=$stop_stage"
#echo "test_sets=$test_sets"
for test_set in "${shard_sets[@]}"; do
{
    echo "prepare test this dataset: $test_set"
}
done
wait


set -e
set -u
set -o pipefail


if [ ${stage} -le 5 ] && [ ${stop_stage} -ge 5 ]; then
  # Test model, please specify the model you want to test by --checkpoint
  cmvn_opts=
  $cmvn && cmvn_opts="--cmvn data/${train_set}/global_cmvn"
  decoding_chunk_size=
  ctc_weight=0.5
  for test_set in "${shard_sets[@]}"; do
  {
    echo "test this dataset: $test_set"
    test_dir=$dir/test_${decode_checkpoint_name}/${test_set}
    mkdir -p $test_dir
    export CUDA_VISIBLE_DEVICES=$gpu_id
    python wenet/bin/recognize.py --gpu $gpu_id \
      --mode $decode_modes \
      --config $dir/train.yaml \
      --data_type shard \
      --test_data data_list/$test_set/data.list \
      --checkpoint $decode_checkpoint \
      --beam_size 10 \
      --batch_size 1 \
      --penalty 0.0 \
      --result_dir $test_dir \
      --ctc_weight $ctc_weight \

#    python tools/compute-wer.py --char=1 --v=1 \
#      data/$test_set/text $test_dir/text_hyp > $test_dir/wer
    echo "$test_set has been decoded!"
  }
  done
  wait

fi
if [ ${stage} -le 6 ] && [ ${stop_stage} -ge 6 ]; then
  decoding_chunk_size=
  ctc_weight=0.5
  for test_set in "${shard_sets[@]}"; do
  {
    echo "comput wer this dataset: $test_set"
    test_dir=$dir/test_${decode_checkpoint_name}/${test_set}
    mkdir -p $test_dir
    python tools/compute-wer.py --char=1 --v=1 \
      data_list/$test_set/text $test_dir/text > $test_dir/wer
    echo "$test_set has been computed!"
  }
  done
  wait

fi

